﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using WebApi.Helpers;
using WebApi.Infrastructure;
using WebApi.Model;
using Microsoft.Extensions.Logging;


using Newtonsoft.Json;
using Renci.SshNet.Messages;
using Microsoft.Extensions.Configuration;


namespace WebApi.Controllers
{
    /// <summary>
    /// 此控制器主要是做通用操作
    /// 1.对字典数据的操作，目前有两个基础数据，Company 单位（装卸货）、Position 位置（装卸货）
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class CommonController : BaseController
    {
        //private readonly ILogger<ValuesController> logger;

        //public CommonController(ILogger<ValuesController> logger)
        //{
        //    logger = logger;
        //}


        private readonly WeighService service;
        private readonly IConfiguration configuration;
        public CommonController(ILogger<WeighController> logger, WeighService _service, IConfiguration _configuration) : base(logger)
        {
            service = _service;
            configuration = _configuration;
        }

        #region 01 字典表相关操作

        /// <summary>
        /// 存入字典信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("WebApiVersion")]
        public ReturnModel WebApiVersion()
        {
            try
            {
                string WebApiVersion = "WebApiVersion_20220909";
                return new ReturnModel { Code = 200, Message = WebApiVersion };
            }
            catch (Exception ex)
            {
                return new ReturnModel { Code = 500, Message = "系统内部错误" };
            }
        }

        /// <summary>
        /// 存入字典信息
        /// </summary>
        /// <param name="insertObj">新增字典对象</param>
        /// <returns></returns>
        [HttpPost("AddDic")]
        public ReturnModel AddDic(Dictionary insertObj)
        {
            try
            {
                //01 数据字段长度判断
                string msg = "";
                if (!CheckFilter(insertObj, out msg))
                {
                    logger.LogError(msg);
                    return new ReturnModel { Code = 500, Message = "新增数据失败：数据字段不能为空。" };
                }
                //02 数据项重复判断
                var db = DbHelper.GetDbConn();
                List<Dictionary> listResult = db.Queryable<Dictionary>()
                    .Where(it => it.DictItemCode == insertObj.DictItemCode)//in 查询
                    .ToList();
                //判断是否存在此code
                if (listResult != null && listResult.Count != 0)
                {
                    logger.LogError("CommonController-->Add:新增数据失败");
                    string tipMsg = "新增数据失败,字典项编号数据不能重复,当前编号信息与编号为：" + listResult[0].DictItemCode + "值为：" + listResult[0].DictItemValue + "的已有数据重复";
                    return new ReturnModel { Code = 500, Message = tipMsg };
                }
                else//新增
                {
                    insertObj.Enable = 1;
                    insertObj.Guid = System.Guid.NewGuid().ToString();
                }
                //03 返回插入行数
                int iExeCount = db.Insertable(insertObj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new ReturnModel();
                }
                else
                {
                    logger.LogError("CommonController-->Add:新增数据失败");
                    return new ReturnModel { Code = 500, Message = "新增数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->Add:" + ex.ToString());
                return new ReturnModel { Code = 500, Message = "系统内部错误" };
            }
        }

        private bool CheckFilter(Dictionary obj, out string msg)
        {
            msg = "";
            bool result = true;
            if (obj == null)
            {
                msg = "数据不能为空";
                result = false;
            }
            if (string.IsNullOrEmpty(obj.DictItemCode))
            {
                msg = "DictItemCode数据不能为空";
                result = false;
            }

            if (string.IsNullOrEmpty(obj.DictItemValue))
            {
                msg = "DictItemValue数据不能为空";
                result = false;
            }
            return result;
        }

        /// <summary>
        /// 检查该父级结点是否有正在使用的子级字典，则不允许删除
        /// </summary>
        private bool CheckInuse(SqlSugar.SqlSugarScope db, string guid)
        {
            if (db.Queryable<Dictionary>().Where(it => it.ParentGuid == guid && it.Enable == 1).Any())
                return true;
            return false;
        }


        /// <summary>
        /// 存入字典信息
        /// </summary>
        /// <param name="obj">更新实体</param>
        /// <returns></returns>
        [HttpPost("UpdataDic")]
        public ReturnModel UpdataDic(Dictionary obj)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                if (CheckInuse(db, obj.Guid) && obj.Enable == 0)
                {
                    logger.LogError("CommonController-->UpdataDic:更新数据失败,此结点下的子级结点有未禁用的故不能禁用此结点");
                    return new ReturnModel { Code = 500, Message = "更新数据失败,此结点下的子级结点有未禁用的故不能禁用此结点" };
                }
                //返回行数
                int iExeCount = db.Updateable(obj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new ReturnModel();
                }
                else
                {
                    logger.LogError("CommonController-->UpdataDic:更新数据失败");
                    return new ReturnModel { Code = 500, Message = "新增数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->UpdataDic:" + ex.ToString());
                return new ReturnModel { Code = 500, Message = "系统内部错误" };
            }
        }

        /// <summary>
        /// 存入字典信息
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns></returns>
        [HttpPost("DeleteDic")]
        public ReturnModel DeleteDic(Dictionary model)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                if (CheckInuse(db, model.Guid))
                {
                    logger.LogError("CommonController-->DeleteDic:删除数据失败,此结点下的子级结点有未禁用的故不能禁用此结点");
                    return new ReturnModel { Code = 500, Message = "删除数据失败,此结点下的子级结点有未禁用的故不能禁用此结点" };
                }

                int iExeCount = db.Deleteable<Dictionary>().Where(it => it.Guid == model.Guid).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new ReturnModel();
                }
                else
                {
                    logger.LogError("CommonController-->DeleteDic:删除数据失败");
                    return new ReturnModel { Code = 500, Message = "删除数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->DeleteDic:" + ex.ToString());
                return new ReturnModel { Code = 500, Message = "系统内部错误" };
            }
        }

        /// <summary>
        /// 查询所有字典信息（启用和未启用的）
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetAllDic")]
        public List<Dictionary> GetAllDic()
        {
            try
            {
                var db = DbHelper.GetDbConn();
                List<Dictionary> lsit = db.Queryable<Dictionary>()
                    .ToList();
                if (lsit != null && lsit.Count != 0)
                {
                    return lsit;
                }
                else
                {
                    logger.LogError("CommonController-->GetDic:查询数据失败");
                    return null;
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetDic:" + ex.ToString());
                return null;
            }
        }

        /// <summary>
        /// 查询字典信息（只有启用的）
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetDic")]
        public List<Dictionary> GetDic()
        {
            try
            {
                var db = DbHelper.GetDbConn();
                List<Dictionary> lsit = db.Queryable<Dictionary>()
                    .Where(it => it.Enable == 1)//in 查询
                    .ToList();

                if (lsit != null && lsit.Count != 0)
                {
                    return lsit;
                }
                else
                {
                    logger.LogError("CommonController-->GetDic:查询数据失败");
                    return null;
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetDic:" + ex.ToString());
                return null;
            }
        }

        /// <summary>
        /// 查询字典信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetDicByDicType")]
        public List<Dictionary> GetDicByDicType(string DicType)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                List<Dictionary> lsit;
                if (string.IsNullOrEmpty(DicType))
                {
                    lsit = db.Queryable<Dictionary>()
                                .LeftJoin<Dictionary>((o, cus) => o.Guid == cus.ParentGuid && cus.Enable == 1)
                                .Where(o => o.ParentGuid == "0" && o.Enable == 1)//in 查询
                                .Select((o, cus) => new Dictionary { ParentGuid = o.Guid, ParentCode = o.DictItemValue, Id = cus.Id, DictItemValue = cus.DictItemValue, DictItemCode = cus.DictItemCode, DictDescribe = cus.DictDescribe, Enable = cus.Enable })
                                .ToList();
                }
                else
                {
                    DicType = DicType.Replace('，', ',');
                    var arrayDicType = DicType.Split(',');
                    if (arrayDicType != null && arrayDicType.Length > 0)
                    {
                        lsit = db.Queryable<Dictionary>()
                                .LeftJoin<Dictionary>((o, cus) => o.Guid == cus.ParentGuid)
                                .Where(o => o.ParentGuid == "0" && arrayDicType.Contains(o.DictItemValue))//in 查询
                                .Select((o, cus) => new Dictionary { ParentGuid = o.Guid, ParentCode = o.DictItemValue, Id = cus.Id, DictItemValue = cus.DictItemValue, DictItemCode = cus.DictItemCode, DictDescribe = cus.DictDescribe, Enable = cus.Enable })
                                .ToList();
                    }
                    else
                    {
                        lsit = null;
                    }
                }
                if (lsit != null && lsit.Count != 0)
                {
                    return lsit;
                }
                else
                {
                    logger.LogError("CommonController-->GetDicByDicType:条件" + DicType + "查询数据失败");
                    return null;
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetDicByDicType:" + ex.ToString());
                return null;
            }
        }

        #endregion

        #region 02 备案表相关操作
        /// <summary>
        /// 新增 备案信息
        /// </summary>
        /// <param name="entity">备案信息</param>
        /// <returns></returns>
        [HttpPost("AddPutOnRecord")]
        public ContentResult AddPutOnRecord(PutOnRecord entity)
        {
            try
            {
                string msg;
                //01 数据字段非空判断
                if (!CheckFilter_PutOnRecord(entity, out msg))
                {
                    logger.LogError(msg);
                    return Content(InterfaceUtil.GetJsonObject(201, "", "新增失败, 字段为空").ToString());
                }
                entity.CreatTime = DateTime.Now;
                entity.Today = DateTime.Now;
                entity.Guid = System.Guid.NewGuid().ToString();
                entity.RemainingWeight = entity.TotalWeight;
                entity.TransportUnitBalance = entity.TransportUnitTotalAmount;


                //02 重复判断
                var db = DbHelper.GetDbConn();
                var temp = db.Queryable<PutOnRecord>().Where(it => it.YNumber == entity.YNumber).ToList();
                if (temp != null && temp.Count != 0)
                {
                    logger.LogError("CommonController-->AddPutOnRecord:新增失败, 备案号重复");
                    return Content(InterfaceUtil.GetJsonObject(201, "", "新增失败, 备案号重复").ToString());
                }
                //03 新增返回插入行数
                int iExeCount = db.Insertable(entity).ExecuteCommand(); //都是参数化实现
                if (iExeCount == 1)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, "", "新增数据成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->AddPutOnRecord:新增数据失败");
                    return Content(InterfaceUtil.GetJsonObject(201, "", "新增失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->AddPutOnRecord:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, "", "新增出错").ToString());
            }
        }
        private bool CheckFilter_PutOnRecord(PutOnRecord obj, out string msg)
        {
            msg = "";
            bool result = true;
            if (obj == null)
            {
                msg += "参数不能为空;";
                result = false;
            }

            if (string.IsNullOrEmpty(obj.OwnerOfCargoUnit))
            {
                msg += "货主单位不能为空;";
                result = false;
            }

            if (string.IsNullOrEmpty(obj.GoodsName))
            {
                msg += "货名不能为空;";
                result = false;
            }

            if (obj.UnitPrice != null && obj.UnitPrice <= 0)
            {
                msg += "单价不能为空;";
                result = false;
            }

            if (string.IsNullOrEmpty(obj.TransportUnit))
            {
                msg += "运输单位不能为空;";
                result = false;
            }

            if (obj.TransportUnitTotalAmount != null && obj.TransportUnitTotalAmount <= 0)
            {
                msg += "运输单位账户总额不能为空;";
                result = false;
            }

            if (obj.StartDate == null)
            {
                msg += "有效期限开始日期不能为空;";
                result = false;
            }
            if (obj.EndDate == null)
            {
                msg += "有效期限结束日期不能为空;";
                result = false;
            }

            if (obj.StartDate != null && obj.EndDate != null)
            {
                if (obj.StartDate > obj.EndDate)
                {
                    msg += "有效期限结束日期不能早于有效期限开始日期为空;";
                    result = false;
                }
            }
            if (string.IsNullOrEmpty(obj.PlateList))
            {
                msg += "车牌号列表不能为空;";
                result = false;
            }
            return result;
        }

        /// <summary>
        /// 通过备案呈 查询备案信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetByYNumber")]
        public ContentResult GetByYNumber(string strYNumber)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                PutOnRecord entity = db.Queryable<PutOnRecord>().First(it => it.YNumber == strYNumber);
                if (entity != null)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, entity, "查询成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->GetByYNumber:查询备案信息失败");
                    return Content(InterfaceUtil.GetJsonObject(201, "", "查询失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetByYNumber:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, "", "查询出错").ToString());
            }
        }

        /// <summary>
        /// 根据有效期限 查询备案信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetPutOnRecordList")]
        public ContentResult GetPutOnRecordList(string GoodsName, string StartDate, string EndDate)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                string sql = "";
                if (!string.IsNullOrEmpty(GoodsName))
                {
                    sql += " t.GoodsName='" + GoodsName + "'";
                }
                if (!string.IsNullOrEmpty(StartDate) && !string.IsNullOrEmpty(EndDate))
                {
                    DateTime date1, date2;
                    //字符串转日期格式
                    try
                    {
                        date1 = Convert.ToDateTime(StartDate);
                        date2 = Convert.ToDateTime(EndDate);
                        sql += string.Format(" and t.StartDate >= '{0}' and t.EndDate < '{1}' ", date1.ToString("yyyy-MM-dd"), date2.ToString("yyyy-MM-dd"));
                    }
                    catch
                    {
                    }
                }
                var lst = db.Queryable<PutOnRecord>("t").Where(sql).ToList();

                if (lst != null)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, lst, "查询成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->GetPutOnRecordList:查询备案信息失败");
                    return Content(InterfaceUtil.GetJsonObject(201, "", "查询失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetPutOnRecordList:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, "", "查询出错").ToString());
            }
        }

        /// <summary>
        /// 查询所有备案信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetAllPutOnRecord")]
        public ContentResult GetAllPutOnRecord()
        {
            try
            {
                var db = DbHelper.GetDbConn();
                var lst = db.Queryable<PutOnRecord>().ToList();

                if (lst != null)
                {
                    //GetJsonObject(int code,int count, object data, string message)
                    return Content(InterfaceUtil.GetJsonObject(200, lst.Count, lst, "查询成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->GetPutOnRecordList:查询备案信息失败");
                    return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetPutOnRecordList:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询出错").ToString());
            }
        }

        /// <summary>
        /// 查询所有备案信息
        /// </summary>
        /// <param name="YNumber">备案号</param>
        /// <param name="StartDate">备案有效期开始日期</param>
        /// <param name="EndDate">备案有效期结束日期</param>
        /// <returns></returns>
        [HttpGet("GetPutOnRecordByParameter")]
        public ContentResult GetPutOnRecordByParameter(string YNumber, string StartDate, string EndDate)
        {
            try
            {
                var db = DbHelper.GetDbConn();

                string sql = "";
                if (!string.IsNullOrEmpty(YNumber))
                {
                    sql += " t.YNumber like '%" + YNumber + "%'";
                }
                if (!string.IsNullOrEmpty(StartDate) && !string.IsNullOrEmpty(EndDate))
                {
                    DateTime date1, date2;
                    //字符串转日期格式
                    try
                    {
                        date1 = Convert.ToDateTime(StartDate);
                        date2 = Convert.ToDateTime(EndDate);
                        sql += string.Format(" and t.StartDate >= '{0}' and t.EndDate < '{1}' ", date1.ToString("yyyy-MM-dd"), date2.ToString("yyyy-MM-dd"));
                    }
                    catch
                    {
                    }
                }

                var lst = db.Queryable<PutOnRecord>("t").Where(sql).ToList();

                if (lst != null)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, lst.Count, lst, "查询成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->GetPutOnRecordList:查询备案信息失败");
                    return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetPutOnRecordList:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询出错").ToString());
            }
        }




        /// <summary>
        /// 修改 备案信息
        /// </summary>
        /// <param name="entity">备案信息</param>
        /// <returns></returns>
        [HttpPost("UpdatePutOnRecord")]
        public ContentResult UpdatePutOnRecord(PutOnRecord entity)
        {
            try
            {
                //根据主键更新单条
                var db = DbHelper.GetDbConn();
                var result = db.Updateable(entity).ExecuteCommand();
                if (result == 1)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, "", "修改数据成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->UpdatePutOnRecord:修改数据失败");
                    return Content(InterfaceUtil.GetJsonObject(201, "", "修改失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->UpdatePutOnRecord:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, "", "修改出错").ToString());
            }
        }

        /// <summary>
        /// 删除 备案信息
        /// </summary>
        /// <param name="Id">运输备案号Id</param>
        /// <returns></returns>
        [HttpPost("DeletePutOnRecord")]
        public ContentResult DeletePutOnRecord(int Id)
        {
            try
            {
                //单个实体
                var db = DbHelper.GetDbConn();
                var result = db.Deleteable<PutOnRecord>().Where(new PutOnRecord() { ID = Id }).ExecuteCommand();
                if (result == 1)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, "", "删除数据成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->DeletePutOnRecord:删除数据失败");
                    return Content(InterfaceUtil.GetJsonObject(201, "", "删除失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->DeletePutOnRecord:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, "", "删除出错").ToString());
            }
        }
        #endregion


        /// <summary>
        /// 根据卡号和入场状态获取对应的注册信息
        /// </summary>
        /// <param name="cardNum">卡号</param>
        /// <param name="status">状态：-1：卡坏了，0：未使用，1：已入场，2：已出厂</param>
        /// <returns></returns>
        [HttpGet("GetRegisterInfo")]
        // GET: api/<ValuesController>
        public PictureResult GetRegisterInfo([FromQuery] string cardNum, [FromQuery] int status)
        {
            using var db = DbHelper.GetDbConn();
            var data = db.Queryable<RegisterInfo>().Where(it => it.ICardNum.Equals(cardNum) && it.CardStatus == status)
                .First();
            if (data == null)
            {
                return new PictureResult()
                {
                    code = 404,
                    message = "未找到对应数据"
                };
            }

            return new PictureResult()
            {
                code = 200,
                message = "成功",
                data = data
            };
        }

        #region 03 黑名单相关操作
        /// <summary>
        /// 查询黑名单信息
        /// </summary>
        /// <param name="BlackListValue">黑名单值</param>
        /// <returns></returns>
        [HttpGet("GetBlackListByParameter")]
        public ContentResult GetBlackListByParameter(string BlackListValue)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                List<BlackList> lst = new List<BlackList>();
                if (!string.IsNullOrEmpty(BlackListValue))
                {
                    lst = db.Queryable<BlackList>().Where(it => it.BlackListValue.Contains(BlackListValue)).ToList();
                }
                else
                {
                    lst = db.Queryable<BlackList>().ToList();
                }

                if (lst != null)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, lst.Count, lst, "查询成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->GetBlackListByParameter:查询黑名单信息失败");
                    return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetBlackListByParameter:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询出错").ToString());
            }
        }

        /// <summary>
        /// 查询所有黑名单信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetAllBlackList")]
        public ContentResult GetAllBlackList()
        {
            try
            {
                var db = DbHelper.GetDbConn();
                var lst = db.Queryable<BlackList>().ToList();

                if (lst != null)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, lst.Count, lst, "查询成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->GetAllBlackList:查询黑名单信息失败");
                    return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetAllBlackList:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询出错").ToString());
            }
        }

        /// <summary>
        /// 新增 黑名单信息
        /// </summary>
        /// <param name="insertObj">黑名单信息</param>
        /// <returns></returns>
        [HttpPost("AddBlackList")]
        public ReturnModel AddBlackList(BlackList insertObj)
        {
            try
            {
                //01 数据字段长度判断
                string msg = "";
                if (insertObj == null || insertObj.BlackListValue == "")
                {
                    logger.LogError(msg);
                    return new ReturnModel { Code = 500, Message = "新增数据失败：数据字段不能为空。" };
                }
                //02 数据项重复判断
                var db = DbHelper.GetDbConn();
                List<BlackList> listResult = db.Queryable<BlackList>()
                    .Where(it => it.BlackListValue == insertObj.BlackListValue && it.Type == insertObj.Type)//in 查询
                    .ToList();
                //判断是否存在此code
                if (listResult != null && listResult.Count != 0)
                {
                    logger.LogError("CommonController-->AddBlackList:新增数据失败");
                    string tipMsg = "新增数据失败,黑名单不能重复";
                    return new ReturnModel { Code = 500, Message = tipMsg };
                }
                //03 返回插入行数
                int iExeCount = db.Insertable(insertObj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new ReturnModel();
                }
                else
                {
                    logger.LogError("CommonController-->AddBlackList:新增数据失败");
                    return new ReturnModel { Code = 500, Message = "新增数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->AddBlackList:" + ex.ToString());
                return new ReturnModel { Code = 500, Message = "系统内部错误" };
            }
        }

        /// <summary>
        /// 更新黑名单信息
        /// </summary>
        /// <param name="obj">更新实体</param>
        /// <returns></returns>
        [HttpPost("UpdataBlackList")]
        public ReturnModel UpdataBlackList(BlackList obj)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                if (db.Queryable<BlackList>().Where(it => it.Id != obj.Id && it.Type == obj.Type && it.BlackListValue == obj.BlackListValue).Any())
                {
                    logger.LogError("CommonController-->UpdataBlackList:更新数据失败,此数据重复");
                    return new ReturnModel { Code = 500, Message = "更新数据失败,此数据重复" };
                }
                //返回行数
                int iExeCount = db.Updateable(obj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new ReturnModel();
                }
                else
                {
                    logger.LogError("CommonController-->UpdataBlackList:更新数据失败");
                    return new ReturnModel { Code = 500, Message = "新增数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->UpdataBlackList:" + ex.ToString());
                return new ReturnModel { Code = 500, Message = "系统内部错误" };
            }
        }

        /// <summary>
        /// 删除 备案信息
        /// </summary>
        /// <param name="obj">实体，但只用id</param>
        /// <returns></returns>
        [HttpPost("DeleteBlackList")]
        public ReturnModel DeleteBlackList(BlackList obj)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                var result = db.Deleteable<BlackList>().Where(new BlackList() { Id = obj.Id }).ExecuteCommand();
                string msg = "";
                if (result == 1)
                {
                    msg = "CommonController-->DeleteBlackList:删除数据成功," + "删除黑名单类型：" + obj.Type + " 黑名单数据值：" + obj.BlackListValue;
                    logger.LogError(msg);
                    return new ReturnModel { Code = 200, Message = "删除数据成功" };
                }
                else
                {
                    logger.LogError("CommonController-->DeleteBlackList:删除数据失败");
                    return new ReturnModel { Code = 500, Message = "删除数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->DeleteBlackList:" + ex.ToString());
                return new ReturnModel { Code = 500, Message = "删除出错" };
            }
        }
        #endregion

        //说明：这些信息都是集控那边维护进去
        #region 04 基础数据相关

        #region 货物

        /// <summary>
        /// 查询所有货物信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetProductList")]
        public ContentResult GetProductList()
        {
            try
            {
                var db = DbHelper.GetDbConn();
                List<ProductList> lst = new List<ProductList>();
                lst = db.Queryable<ProductList>().ToList();
                if (lst != null)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, lst.Count, lst, "查询成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->GetProductList:查询货物信息失败");
                    return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetProductList:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询出错").ToString());
            }
        }

        /// <summary>
        /// 根据货物查询信息
        /// </summary>
        /// <param name="Product">货物</param>
        /// <returns></returns>
        [HttpPost("GetProductByParameter")]
        public BackInfo GetProductByParameter([FromForm] string Product)
        {
            BackInfo bi = new BackInfo();
            try
            {
                var db = DbHelper.GetDbConn();
                List<ProductList> lst = new List<ProductList>();
                if (!string.IsNullOrEmpty(Product))
                {
                    lst = db.Queryable<ProductList>().Where(it => it.product.Contains(Product)).ToList();
                }
                else
                {
                    lst = db.Queryable<ProductList>().ToList();
                }
                bi.code = 200;
                bi.data = lst;
                bi.message = "查询成功";
                return bi;
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "";
                bi.message = "查询出错";
                logger.LogError("CommonController-->GetReceiverByParameter:查询自定义基础数据信息出错" + ex.ToString());
                return bi;
            }
        }

        /// <summary>
        /// 新增 货物
        /// </summary>
        /// <param name="insertObj">货物</param>
        /// <returns></returns>
        [HttpPost("AddProductList")]
        public BackInfo AddProductList(ProductList insertObj)
        {
            try
            {
                //01 数据字段长度判断
                string msg = "";
                if (insertObj == null || insertObj.product == "")
                {
                    logger.LogError(msg);
                    return new BackInfo { code = 201, message = "新增数据失败：货物字段不能为空。" };
                }
                //02 数据项重复判断
                var db = DbHelper.GetDbConn();
                List<ProductList> listResult = db.Queryable<ProductList>()
                    .Where(it => it.product == insertObj.product)//in 查询
                    .ToList();
                //判断是否存在此code
                if (listResult != null && listResult.Count != 0)
                {
                    logger.LogError("CommonController-->AddProductList:新增数据失败");
                    string tipMsg = "新增数据失败,货物不能重复";
                    return new BackInfo { code = 201, message = tipMsg };
                }
                //03 返回插入行数
                int iExeCount = db.Insertable(insertObj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new BackInfo { code = 200, message = "新增成功" };
                }
                else
                {
                    LogToDB("ProductList", "新增", JsonConvert.SerializeObject(insertObj), "失败", nameof(AddProductList) + "新增数据失败");
                    return new BackInfo { code = 201, message = "新增数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->AddProductList:" + ex.ToString());
                LogToDB("ProductList", "新增", JsonConvert.SerializeObject(insertObj), "出错", nameof(AddProductList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }


        /// <summary>
        /// 修改 货物
        /// </summary>
        /// <param name="obj">货物</param>
        /// <returns></returns>
        [HttpPost("UpdataProductList")]
        public BackInfo UpdataProductList(ProductList obj)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                if (db.Queryable<ProductList>().Where(it => it.id != obj.id && it.product == obj.product).Any())
                {
                    logger.LogError("CommonController-->UpdataProductList:更新数据失败,货物重复");
                    return new BackInfo { code = 201, message = "更新数据失败,货物重复。" };
                }
                //返回行数
                int iExeCount = db.Updateable(obj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new BackInfo { code = 200, message = "修改成功" };
                }
                else
                {
                    logger.LogError("CommonController-->UpdataProductList:更新数据失败");
                    LogToDB("ProductList", "修改", JsonConvert.SerializeObject(obj), "失败", nameof(UpdataProductList) + "更新数据失败");
                    return new BackInfo { code = 201, message = "更新数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->UpdataProductList:" + ex.ToString());
                LogToDB("ProductList", "修改", JsonConvert.SerializeObject(obj), "出错", nameof(UpdataProductList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }


        /// <summary>
        /// 删除 货物
        /// </summary>
        /// <param name="obj">实体，但只用id</param>
        /// <returns></returns>
        [HttpPost("DeleteProductList")]
        public BackInfo DeleteProductList(ProductList obj)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                var result = db.Deleteable<ProductList>().Where(new ProductList() { id = obj.id }).ExecuteCommand();
                string msg = "";
                if (result == 1)
                {
                    msg = "CommonController-->DeleteProductList:删除成功";
                    logger.LogError(msg);
                    return new BackInfo { code = 200, message = "删除成功" };
                }
                else
                {
                    logger.LogError("CommonController-->DeleteProductList:删除数据失败");
                    LogToDB("ProductList", "删除", JsonConvert.SerializeObject(obj), "失败", nameof(DeleteReceiverList) + "删除数据失败");
                    return new BackInfo { code = 201, message = "删除数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->DeleteProductList:" + ex.ToString());
                LogToDB("ProductList", "删除", JsonConvert.SerializeObject(obj), "出错", nameof(DeleteReceiverList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }

        #endregion

        #region 发货单位

        /// <summary>
        /// 查询所有发货单位信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetSenderList")]
        public ContentResult GetSenderList()
        {
            try
            {
                var db = DbHelper.GetDbConn();
                List<SenderList> lst = new List<SenderList>();
                lst = db.Queryable<SenderList>().ToList();
                if (lst != null)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, lst.Count, lst, "查询成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->GetSenderList:查询发货单位信息失败");
                    return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetSenderList:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询出错").ToString());
            }
        }

        /// <summary>
        /// 根据参数查询信息
        /// </summary>
        /// <param name="Sender">收货单位</param>
        /// <returns></returns>
        [HttpPost("GetSenderByParameter")]
        public BackInfo GetSenderByParameter([FromForm] string Sender)
        {
            BackInfo bi = new BackInfo();
            try
            {
                var db = DbHelper.GetDbConn();
                List<SenderList> lst = new List<SenderList>();
                if (!string.IsNullOrEmpty(Sender))
                {
                    lst = db.Queryable<SenderList>().Where(it => it.sender.Contains(Sender)).ToList();
                }
                else
                {
                    lst = db.Queryable<SenderList>().ToList();
                }
                bi.code = 200;
                bi.data = lst;
                bi.message = "查询成功";
                return bi;
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "";
                bi.message = "查询出错";
                logger.LogError("CommonController-->GetSenderByParameter:查询自定义基础数据信息出错" + ex.ToString());
                return bi;
            }
        }


        /// <summary>
        /// 新增 发货单位
        /// </summary>
        /// <param name="insertObj">发货单位</param>
        /// <returns></returns>
        [HttpPost("AddSenderList")]
        public BackInfo AddSenderList(SenderList insertObj)
        {
            try
            {
                //01 数据字段长度判断
                string msg = "";
                if (insertObj == null || insertObj.sender == "")
                {
                    logger.LogError(msg);
                    return new BackInfo { code = 201, message = "新增数据失败：发货单位字段不能为空。" };
                }
                //02 数据项重复判断
                var db = DbHelper.GetDbConn();
                List<SenderList> listResult = db.Queryable<SenderList>()
                    .Where(it => it.sender == insertObj.sender)//in 查询
                    .ToList();
                //判断是否存在此code
                if (listResult != null && listResult.Count != 0)
                {
                    logger.LogError("CommonController-->AddSenderList:新增数据失败");
                    string tipMsg = "新增数据失败,发货单位不能重复";
                    return new BackInfo { code = 201, message = tipMsg };
                }
                //03 返回插入行数
                int iExeCount = db.Insertable(insertObj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new BackInfo { code = 200, message = "新增成功" };
                }
                else
                {
                    LogToDB("SenderList", "新增", JsonConvert.SerializeObject(insertObj), "失败", nameof(AddSenderList) + "新增数据失败");
                    return new BackInfo { code = 201, message = "新增数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->AddBlackList:" + ex.ToString());
                LogToDB("SenderList", "新增", JsonConvert.SerializeObject(insertObj), "出错", nameof(AddSenderList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }


        /// <summary>
        /// 修改 发货单位
        /// </summary>
        /// <param name="obj">发货单位</param>
        /// <returns></returns>
        [HttpPost("UpdataSenderList")]
        public BackInfo UpdataSenderList(SenderList obj)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                if (db.Queryable<SenderList>().Where(it => it.id != obj.id && it.sender == obj.sender).Any())
                {
                    logger.LogError("CommonController-->UpdataSenderList:更新数据失败,发货单位重复");
                    return new BackInfo { code = 201, message = "更新数据失败,发货单位重复。" };
                }
                //返回行数
                int iExeCount = db.Updateable(obj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new BackInfo { code = 200, message = "修改成功" };
                }
                else
                {
                    logger.LogError("CommonController-->UpdataSenderList:更新数据失败");
                    LogToDB("SenderList", "修改", JsonConvert.SerializeObject(obj), "失败", nameof(UpdataSenderList) + "更新数据失败");
                    return new BackInfo { code = 201, message = "更新数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->UpdataSenderList:" + ex.ToString());
                LogToDB("SenderList", "修改", JsonConvert.SerializeObject(obj), "出错", nameof(UpdataSenderList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }


        /// <summary>
        /// 删除 发货单位
        /// </summary>
        /// <param name="obj">实体，但只用id</param>
        /// <returns></returns>
        [HttpPost("DeleteSenderList")]
        public BackInfo DeleteSenderList(SenderList obj)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                var result = db.Deleteable<SenderList>().Where(new SenderList() { id = obj.id }).ExecuteCommand();
                string msg = "";
                if (result == 1)
                {
                    msg = "CommonController-->DeleteSenderList:删除成功";
                    logger.LogError(msg);
                    return new BackInfo { code = 200, message = "删除成功" };
                }
                else
                {
                    logger.LogError("CommonController-->DeleteBlackList:删除数据失败");
                    LogToDB("SenderList", "删除", JsonConvert.SerializeObject(obj), "失败", nameof(DeleteSenderList) + "删除数据失败");
                    return new BackInfo { code = 201, message = "删除数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->DeleteBlackList:" + ex.ToString());
                LogToDB("SenderList", "删除", JsonConvert.SerializeObject(obj), "出错", nameof(DeleteSenderList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }

        #endregion


        #region 收货单位

        /// <summary>
        /// 查询所有收货单位信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetReceiverList")]
        public ContentResult GetReceiverList()
        {
            try
            {
                var db = DbHelper.GetDbConn();
                List<ReceiverList> lst = new List<ReceiverList>();
                lst = db.Queryable<ReceiverList>().ToList();
                if (lst != null)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, lst.Count, lst, "查询成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->GetBlackListByParameter:查询收货单位信息失败");
                    return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetReceiverList:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询出错").ToString());
            }
        }

        /// <summary>
        /// 根据参数查询信息
        /// </summary>
        /// <param name="Receiver">发货单位</param>
        /// <returns></returns>
        [HttpPost("GetReceiverByParameter")]
        public BackInfo GetReceiverByParameter([FromForm] string Receiver)
        {
            BackInfo bi = new BackInfo();
            try
            {
                var db = DbHelper.GetDbConn();
                List<ReceiverList> lst = new List<ReceiverList>();
                if (!string.IsNullOrEmpty(Receiver))
                {
                    lst = db.Queryable<ReceiverList>().Where(it => it.receiver.Contains(Receiver)).ToList();
                }
                else
                {
                    lst = db.Queryable<ReceiverList>().ToList();                    
                }
                bi.code = 200;
                bi.data = lst;
                bi.message = "查询成功";
                return bi;
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "";
                bi.message = "查询出错";
                logger.LogError("CommonController-->GetReceiverByParameter:查询自定义基础数据信息出错" + ex.ToString());
                return bi;
            }
        }

        /// <summary>
        /// 新增 收货单位
        /// </summary>
        /// <param name="insertObj">收货单位</param>
        /// <returns></returns>
        [HttpPost("AddReceiverList")]
        public BackInfo AddReceiverList(ReceiverList insertObj)
        {
            try
            {
                //01 数据字段长度判断
                string msg = "";
                if (insertObj == null || insertObj.receiver == "")
                {
                    logger.LogError(msg);
                    return new BackInfo { code = 201, message = "新增数据失败：收货单位字段不能为空。" };
                }
                //02 数据项重复判断
                var db = DbHelper.GetDbConn();
                List<ReceiverList> listResult = db.Queryable<ReceiverList>()
                    .Where(it => it.receiver == insertObj.receiver)//in 查询
                    .ToList();
                //判断是否存在此code
                if (listResult != null && listResult.Count != 0)
                {
                    logger.LogError("CommonController-->AddReceiverList:新增数据失败");
                    string tipMsg = "新增数据失败,收货单位不能重复";
                    return new BackInfo { code = 201, message = tipMsg };
                }
                //03 返回插入行数
                int iExeCount = db.Insertable(insertObj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new BackInfo { code = 200, message = "新增成功" };
                }
                else
                {
                    LogToDB("ReceiverList", "新增", JsonConvert.SerializeObject(insertObj), "失败", nameof(AddReceiverList) + "新增数据失败");
                    return new BackInfo { code = 201, message = "新增数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->AddBlackList:" + ex.ToString());
                LogToDB("ReceiverList", "新增", JsonConvert.SerializeObject(insertObj), "出错", nameof(AddReceiverList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }


        /// <summary>
        /// 修改 收货单位
        /// </summary>
        /// <param name="obj">收货单位</param>
        /// <returns></returns>
        [HttpPost("UpdataReceiverList")]
        public BackInfo UpdataReceiverList(ReceiverList obj)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                if (db.Queryable<ReceiverList>().Where(it => it.id != obj.id && it.receiver == obj.receiver).Any())
                {
                    logger.LogError("CommonController-->UpdataReceiverList:更新数据失败,收货单位重复");
                    return new BackInfo { code = 201, message = "更新数据失败,收货单位重复。" };
                }
                //返回行数
                int iExeCount = db.Updateable(obj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new BackInfo { code = 200, message = "修改成功" };
                }
                else
                {
                    logger.LogError("CommonController-->UpdataReceiverList:更新数据失败");
                    LogToDB("ReceiverList", "修改", JsonConvert.SerializeObject(obj), "失败", nameof(UpdataReceiverList) + "更新数据失败");
                    return new BackInfo { code = 201, message = "更新数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->UpdataReceiverList:" + ex.ToString());
                LogToDB("ReceiverList", "修改", JsonConvert.SerializeObject(obj), "出错", nameof(UpdataReceiverList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }


        /// <summary>
        /// 删除 收货单位
        /// </summary>
        /// <param name="obj">实体，但只用id</param>
        /// <returns></returns>
        [HttpPost("DeleteReceiverList")]
        public BackInfo DeleteReceiverList(ReceiverList obj)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                var result = db.Deleteable<ReceiverList>().Where(new ReceiverList() { id = obj.id }).ExecuteCommand();
                string msg = "";
                if (result == 1)
                {
                    msg = "CommonController-->DeleteReceiverList:删除成功" ;
                    logger.LogError(msg);
                    return new BackInfo { code = 200, message = "删除成功" };
                }
                else
                {
                    logger.LogError("CommonController-->DeleteBlackList:删除数据失败");
                    LogToDB("ReceiverList", "删除", JsonConvert.SerializeObject(obj), "失败", nameof(DeleteReceiverList) + "删除数据失败");
                    return new BackInfo { code = 201, message = "删除数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->DeleteBlackList:" + ex.ToString());
                LogToDB("ReceiverList", "删除", JsonConvert.SerializeObject(obj), "出错", nameof(DeleteReceiverList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }
        #endregion

        #region 运输单位

        /// <summary>
        /// 查询所有运输单位信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetTransporterList")]
        public ContentResult GetTransporterList()
        {
            try
            {
                var db = DbHelper.GetDbConn();
                List<TransporterList> lst = new List<TransporterList>();
                lst = db.Queryable<TransporterList>().ToList();
                if (lst != null)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, lst.Count, lst, "查询成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->GetTransporterList:查询运输单位信息失败");
                    return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetTransporterList:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询出错").ToString());
            }
        }

        ///// <summary>
        ///// 根据参数查询信息
        ///// </summary>
        ///// <param name="Receiver">发货单位</param>
        ///// <returns></returns>
        //[HttpPost("GetReceiverByParameter")]
        //public BackInfo GetReceiverByParameter([FromForm] string Receiver)
        //{
        //    BackInfo bi = new BackInfo();
        //    try
        //    {
        //        var db = DbHelper.GetDbConn();
        //        List<ReceiverList> lst = new List<ReceiverList>();
        //        if (!string.IsNullOrEmpty(Receiver))
        //        {
        //            lst = db.Queryable<ReceiverList>().Where(it => it.receiver.Contains(Receiver)).ToList();
        //        }
        //        else
        //        {
        //            lst = db.Queryable<ReceiverList>().ToList();
        //        }
        //        bi.code = 200;
        //        bi.data = lst;
        //        bi.message = "查询成功";
        //        return bi;
        //    }
        //    catch (Exception ex)
        //    {
        //        bi.code = 500;
        //        bi.data = "";
        //        bi.message = "查询出错";
        //        logger.LogError("CommonController-->GetReceiverByParameter:查询自定义基础数据信息出错" + ex.ToString());
        //        return bi;
        //    }
        //}

        ///// <summary>
        ///// 新增 收货单位
        ///// </summary>
        ///// <param name="insertObj">收货单位</param>
        ///// <returns></returns>
        //[HttpPost("AddReceiverList")]
        //public BackInfo AddReceiverList(ReceiverList insertObj)
        //{
        //    try
        //    {
        //        //01 数据字段长度判断
        //        string msg = "";
        //        if (insertObj == null || insertObj.receiver == "")
        //        {
        //            logger.LogError(msg);
        //            return new BackInfo { code = 201, message = "新增数据失败：收货单位字段不能为空。" };
        //        }
        //        //02 数据项重复判断
        //        var db = DbHelper.GetDbConn();
        //        List<ReceiverList> listResult = db.Queryable<ReceiverList>()
        //            .Where(it => it.receiver == insertObj.receiver)//in 查询
        //            .ToList();
        //        //判断是否存在此code
        //        if (listResult != null && listResult.Count != 0)
        //        {
        //            logger.LogError("CommonController-->AddReceiverList:新增数据失败");
        //            string tipMsg = "新增数据失败,收货单位不能重复";
        //            return new BackInfo { code = 201, message = tipMsg };
        //        }
        //        //03 返回插入行数
        //        int iExeCount = db.Insertable(insertObj).ExecuteCommand(); //都是参数化实现                
        //        if (iExeCount == 1)
        //        {
        //            return new BackInfo { code = 200, message = "新增成功" };
        //        }
        //        else
        //        {
        //            LogToDB("ReceiverList", "新增", JsonConvert.SerializeObject(insertObj), "失败", nameof(AddReceiverList) + "新增数据失败");
        //            return new BackInfo { code = 201, message = "新增数据失败" };
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        logger.LogError("CommonController-->AddBlackList:" + ex.ToString());
        //        LogToDB("ReceiverList", "新增", JsonConvert.SerializeObject(insertObj), "出错", nameof(AddReceiverList) + "系统内部错误" + ex.ToString());
        //        return new BackInfo { code = 500, message = "系统内部错误" };
        //    }
        //}


        ///// <summary>
        ///// 修改 收货单位
        ///// </summary>
        ///// <param name="obj">收货单位</param>
        ///// <returns></returns>
        //[HttpPost("UpdataReceiverList")]
        //public BackInfo UpdataReceiverList(ReceiverList obj)
        //{
        //    try
        //    {
        //        var db = DbHelper.GetDbConn();
        //        if (db.Queryable<ReceiverList>().Where(it => it.id != obj.id && it.receiver == obj.receiver).Any())
        //        {
        //            logger.LogError("CommonController-->UpdataReceiverList:更新数据失败,收货单位重复");
        //            return new BackInfo { code = 201, message = "更新数据失败,收货单位重复。" };
        //        }
        //        //返回行数
        //        int iExeCount = db.Updateable(obj).ExecuteCommand(); //都是参数化实现                
        //        if (iExeCount == 1)
        //        {
        //            return new BackInfo { code = 200, message = "修改成功" };
        //        }
        //        else
        //        {
        //            logger.LogError("CommonController-->UpdataReceiverList:更新数据失败");
        //            LogToDB("ReceiverList", "修改", JsonConvert.SerializeObject(obj), "失败", nameof(UpdataReceiverList) + "更新数据失败");
        //            return new BackInfo { code = 201, message = "更新数据失败" };
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        logger.LogError("CommonController-->UpdataReceiverList:" + ex.ToString());
        //        LogToDB("ReceiverList", "修改", JsonConvert.SerializeObject(obj), "出错", nameof(UpdataReceiverList) + "系统内部错误" + ex.ToString());
        //        return new BackInfo { code = 500, message = "系统内部错误" };
        //    }
        //}


        ///// <summary>
        ///// 删除 收货单位
        ///// </summary>
        ///// <param name="obj">实体，但只用id</param>
        ///// <returns></returns>
        //[HttpPost("DeleteReceiverList")]
        //public BackInfo DeleteReceiverList(ReceiverList obj)
        //{
        //    try
        //    {
        //        var db = DbHelper.GetDbConn();
        //        var result = db.Deleteable<ReceiverList>().Where(new ReceiverList() { id = obj.id }).ExecuteCommand();
        //        string msg = "";
        //        if (result == 1)
        //        {
        //            msg = "CommonController-->DeleteReceiverList:删除成功";
        //            logger.LogError(msg);
        //            return new BackInfo { code = 200, message = "删除成功" };
        //        }
        //        else
        //        {
        //            logger.LogError("CommonController-->DeleteBlackList:删除数据失败");
        //            LogToDB("ReceiverList", "删除", JsonConvert.SerializeObject(obj), "失败", nameof(DeleteReceiverList) + "删除数据失败");
        //            return new BackInfo { code = 201, message = "删除数据失败" };
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        logger.LogError("CommonController-->DeleteBlackList:" + ex.ToString());
        //        LogToDB("ReceiverList", "删除", JsonConvert.SerializeObject(obj), "出错", nameof(DeleteReceiverList) + "系统内部错误" + ex.ToString());
        //        return new BackInfo { code = 500, message = "系统内部错误" };
        //    }
        //}
        #endregion

        #endregion


        #region 05 自定义基础数据--类似于字典数据
        //说明：由于前面的那个字典表，结构存在父级，字段较多，使用不灵活，故运用此表存储将来的需要映射的数据
        /// <summary>
        /// 根据数据类型查询信息
        /// </summary>
        /// <param name="BaseDataType">基础数据类型</param>
        /// <returns></returns>
        [HttpPost("GetCustomBaseData")]
        public BackInfo GetCustomBaseData([FromQuery] string BaseDataType)
        {
            BackInfo bi = new BackInfo();
            try
            {
                var db = DbHelper.GetDbConn();
                List<CustomBaseData> lst = new List<CustomBaseData>();
                if (!string.IsNullOrEmpty(BaseDataType))
                {
                    lst = db.Queryable<CustomBaseData>().Where(it => it.BaseDataType == BaseDataType).ToList();
                }
                else
                {
                    bi.code = 500;
                    bi.data = "";
                    bi.message = "请输入基础数据类型";
                    return bi;
                }
                if (lst != null)
                {
                    bi.code = 200;
                    bi.data = lst;
                    bi.message = "查询成功";
                    return bi;
                }
                else
                {
                    bi.code = 201;
                    bi.data = "";
                    bi.message = "没有查询到相应数据";
                    return bi;
                }
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "";
                bi.message = "查询出错";
                logger.LogError("SSMachineController-->GetCustomBaseData:查询自定义基础数据信息出错" + ex.ToString());
                return bi;
            }
        }

        /// <summary>
        /// 根据数据类型查询信息
        /// </summary>
        /// <param name="BaseDataType">基础数据类型</param>
        /// <param name="Source">源</param>
        /// <returns></returns>
        [HttpPost("GetCustomBaseDataByParameter")]
        public BackInfo GetCustomBaseDataByParameter(string BaseDataType, string Source)
        {
            BackInfo bi = new BackInfo();
            try
            {
                var db = DbHelper.GetDbConn();
                List<CustomBaseData> lst = new List<CustomBaseData>();
                if (!string.IsNullOrEmpty(BaseDataType))
                {
                    if (!string.IsNullOrEmpty(Source))
                    {
                        lst = db.Queryable<CustomBaseData>().Where(it => it.BaseDataType == BaseDataType && it.Source.Contains(Source)).ToList();
                    }
                    else
                    {
                        lst = db.Queryable<CustomBaseData>().Where(it => it.BaseDataType == BaseDataType).ToList();
                    }
                }
                else
                {
                    bi.code = 500;
                    bi.data = "";
                    bi.message = "请输入基础数据类型";
                    return bi;
                }
                if (lst != null && lst.Count != 0)
                {
                    bi.code = 200;
                    bi.data = lst;
                    bi.message = "查询成功";
                    return bi;
                }
                else
                {
                    bi.code = 201;
                    bi.data = "";
                    bi.message = "没有查询到相应数据";
                    return bi;
                }
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "";
                bi.message = "查询出错";
                logger.LogError("SSMachineController-->GetCustomBaseData:查询自定义基础数据信息出错" + ex.ToString());
                return bi;
            }
        }
        
        /// <summary>
        /// 查找所有数据
        /// </summary>
        /// <param name="BaseDataType">基础数据类型</param>
        /// <param name="Source">源</param>
        /// <returns></returns>
        [HttpPost("QueryCustomBaseDataByParameter")]
        public BackInfo QueryCustomBaseDataByParameter([FromForm]string BaseDataType, [FromForm] string Source)
        {
            BackInfo bi = new BackInfo();
            try
            {
                var db = DbHelper.GetDbConn();
                List<CustomBaseData> lst = new List<CustomBaseData>();
                if (string.IsNullOrEmpty(BaseDataType) && string.IsNullOrEmpty(Source))
                {
                    lst = db.Queryable<CustomBaseData>().ToList();
                }
                else if (!string.IsNullOrEmpty(BaseDataType) && string.IsNullOrEmpty(Source))
                {
                    lst = db.Queryable<CustomBaseData>().Where(it=>it.BaseDataType == BaseDataType).ToList();
                }
                else if (!string.IsNullOrEmpty(BaseDataType) && !string.IsNullOrEmpty(Source))
                {
                    lst = db.Queryable<CustomBaseData>().Where(it => it.BaseDataType == BaseDataType && it.Source == Source).ToList();
                }
                if (lst != null && lst.Count != 0)
                {
                    bi.code = 200;
                    bi.data = lst;
                    bi.message = "查询成功";
                    return bi;
                }
                else
                {
                    bi.code = 201;
                    bi.data = "";
                    bi.message = "没有查询到相应数据";
                    return bi;
                }
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "";
                bi.message = "查询出错";
                logger.LogError("SSMachineController-->GetCustomBaseData:查询自定义基础数据信息出错" + ex.ToString());
                return bi;
            }
        }

        /// <summary>
        /// 新增 自定义基础数据
        /// </summary>
        /// <param name="insertObj">自定义基础数据</param>
        /// <returns></returns>
        [HttpPost("AddCustomBaseData")]
        public BackInfo AddCustomBaseData(CustomBaseData insertObj)
        {
            BackInfo bi = new BackInfo();
            try
            {
                if (insertObj == null || insertObj.BaseDataType == "" || insertObj.Source == "" || insertObj.Target == "")
                {
                    bi.code = 201;
                    bi.data = "字段空";
                    bi.message = "新增数据失败：数据字段不能为空。";
                }

                var db = DbHelper.GetDbConn();
                List<CustomBaseData> listResult = db.Queryable<CustomBaseData>()
                    .Where(it => it.BaseDataType == insertObj.BaseDataType && it.Source == insertObj.Source && it.Target == insertObj.Target)//in 查询
                    .ToList();
                //判断是否存在此数据
                if (listResult != null && listResult.Count != 0)
                {
                    bi.code = 201;
                    bi.data = "重复";
                    bi.message = "新增数据失败：数据不能重复。";
                    return bi;
                }
                if (db.Queryable<CustomBaseData>().Where(it => it.BaseDataType == insertObj.BaseDataType
                && it.Source == insertObj.Source).Any())
                {
                    bi.code = 201;
                    bi.data = "与已有源字段相同";
                    bi.message = "与已有源字段相同";
                    logger.LogError("SSMachineController-->AddCustomBaseData:新增数据失败,与已有源字段相同");
                    return bi;
                }
                //03 返回插入行数
                int iExeCount = db.Insertable(insertObj).IgnoreColumns(it => it.Id).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    bi.code = 200;
                    bi.data = "新增成功";
                    bi.message = "新增成功";
                    return bi;
                }
                else
                {
                    bi.code = 201;
                    bi.data = "新增数据失败";
                    bi.message = "新增数据失败";
                    return bi;
                }
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "系统内部错误";
                bi.message = "系统内部错误";
                logger.LogError("CommonController-->AddCustomBaseData:" + ex.ToString());
                return bi;
            }
        }
        /// <summary>
        /// 新增 自定义基础数据
        /// </summary>
        /// <param name="updataObj">自定义基础数据</param>
        /// <returns></returns>
        [HttpPost("UpdataCustomBaseData")]
        public BackInfo UpdataCustomBaseData(CustomBaseData updataObj)
        {
            BackInfo bi = new BackInfo();
            try
            {
                var db = DbHelper.GetDbConn();
                if (db.Queryable<CustomBaseData>().Where(it => it.BaseDataType == updataObj.BaseDataType
                && it.Source == updataObj.Source && it.Target == updataObj.Target
                && it.Enable == updataObj.Enable && it.Id != updataObj.Id).Any())
                {
                    bi.code = 201;
                    bi.data = "更新数据失败";
                    bi.message = "更新数据失败,此数据重复";
                    logger.LogError("SSMachineController-->UpdataCustomBaseData:更新数据失败,此数据重复");
                    return bi;
                }

                if (db.Queryable<CustomBaseData>().Where(it => it.BaseDataType == updataObj.BaseDataType
                && it.Source == updataObj.Source && it.Id != updataObj.Id).Any())
                {
                    bi.code = 201;
                    bi.data = "与已有源字段相同";
                    bi.message = "与已有源字段相同";
                    logger.LogError("SSMachineController-->UpdataCustomBaseData:更新数据失败,与已有源字段相同");
                    return bi;
                }
                //信息安全的东西报表导入统计的，
                if (updataObj == null || updataObj.BaseDataType == "" || updataObj.Source == "")
                {
                    bi.code = 201;
                    bi.data = "字段空";
                    bi.message = "修改数据失败：数据字段不能为空。";
                }

                //返回行数
                int iExeCount = db.Updateable(updataObj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    bi.code = 200;
                    bi.data = "更新成功";
                    bi.message = "更新成功";
                    return bi;
                }
                else
                {
                    bi.code = 201;
                    bi.data = "更新失败";
                    bi.message = "更新失败";
                    return bi;
                }
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "系统内部错误";
                bi.message = "系统内部错误";
                logger.LogError("CommonController-->UpdataCustomBaseData:" + ex.ToString());
                return bi;
            }
        }

        /// <summary>
        /// 删除 自定义基础数据
        /// </summary>
        /// <param name="obj">实体，但只用id</param>
        /// <returns></returns>
        [HttpPost("DeleteCustomBaseData")]
        public BackInfo DeleteCustomBaseData(CustomBaseData obj)
        {
            BackInfo bi = new BackInfo();
            string msg = "";
            try
            {
                var db = DbHelper.GetDbConn();
                var result = db.Deleteable<CustomBaseData>().Where(new CustomBaseData() { Id = obj.Id }).ExecuteCommand();
                if (result == 1)
                {
                    bi.code = 200;
                    bi.data = "删除数据成功";
                    bi.message = "删除数据成功";
                    return bi;
                }
                else
                {
                    bi.code = 201;
                    bi.data = "删除数据失败";
                    bi.message = "删除数据失败";
                    return bi;
                }
            }
            catch (Exception ex)
            {
                msg = "CommonController-->DeleteCustomBaseData:删除出错" + ex.ToString();
                logger.LogError(msg);
                bi.code = 500;
                bi.data = "删除出错";
                bi.message = msg;
                return bi;
            }
        }



        #endregion

        #region 06 验证车牌列表相关操作接口
        //需求说明：客户管理端每天，维护可以拉某种货物的车辆列表，
        //1.制卡时根据日期、货物、去列表里查询所填车牌号是否在里面，没有则不让制卡
        //2.如果管理端当天没有维护，某种货物的可拉列表，则可以制卡

        #region 先折叠，以后再册
        ///// <summary>
        ///// 根据数据类型查询信息
        ///// </summary>
        ///// <param name="Date">日期</param>
        ///// <param name="GoodsName">货物名字</param>
        ///// <returns></returns>
        //[HttpPost("QueryVerifyPlateList")]
        //public BackInfo QueryVerifyPlateList([FromForm]string Date, [FromForm] string GoodsName)
        //{
        //    BackInfo bi = new BackInfo();
        //    try
        //    {
        //        if (string.IsNullOrEmpty(GoodsName))
        //        {
        //            GoodsName = "";
        //        }
        //        var db = DbHelper.GetDbConn();
        //        List<VerifyPlateList> lst = new List<VerifyPlateList>();
        //        DateTime dt;
        //        if (!string.IsNullOrEmpty(Date))
        //        {
        //            if (!DateTime.TryParse(Date, out dt))
        //            {
        //                bi.code = 201;
        //                bi.data = "";
        //                bi.message = "请输入正确的日期";
        //                return bi;
        //            }
        //            lst = db.Queryable<VerifyPlateList>().Where(it => it.VerifyDate.Date == dt.Date && it.GoodsName.Contains(GoodsName)).ToList();                
        //        }
        //        else
        //        {
        //            lst = db.Queryable<VerifyPlateList>().ToList();
        //        }
        //        bi.code = 200;
        //        bi.data = lst;
        //        bi.message = "查询成功";
        //        return bi;
        //    }
        //    catch (Exception ex)
        //    {
        //        bi.code = 500;
        //        bi.data = "";
        //        bi.message = "查询出错";
        //        logger.LogError("CommonController-->QueryVerifyPlateList:查询自定义基础数据信息出错" + ex.ToString());
        //        return bi;
        //    }
        //}

        #endregion

        /// <summary>
        /// 根据数据类型查询信息
        /// </summary>
        /// <param name="Date">日期</param>
        /// <returns></returns>
        [HttpPost("QueryVerifyPlateList")]
        public BackInfo QueryVerifyPlateList([FromForm] string Date)
        {
            BackInfo bi = new BackInfo();
            try
            {
                var db = DbHelper.GetDbConn();
                List<VerifyPlateList> lst = new List<VerifyPlateList>();
                DateTime dt;
                if (!string.IsNullOrEmpty(Date))
                {
                    if (!DateTime.TryParse(Date, out dt))
                    {
                        bi.code = 201;
                        bi.data = "";
                        bi.message = "请输入正确的日期";
                        return bi;
                    }
                    lst = db.Queryable<VerifyPlateList>().Where(it => it.VerifyDate.Date == dt.Date).ToList();
                }
                else
                {
                    lst = db.Queryable<VerifyPlateList>().ToList();
                }
                bi.code = 200;
                bi.data = lst;
                bi.message = "查询成功";
                return bi;
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "";
                bi.message = "查询出错";
                logger.LogError("CommonController-->QueryVerifyPlateList:查询自定义基础数据信息出错" + ex.ToString());
                return bi;
            }
        }

        /// <summary>
        /// 根据数据类型查询信息
        /// </summary>
        /// <param name="Date">日期</param>
        /// <param name="GoodsName">货物名字</param>
        /// <param name="Plate">货物名字</param>
        /// <returns></returns>
        [HttpPost("VerifyPlate")]
        public BackInfo VerifyPlate([FromForm] string Date, [FromForm] string GoodsName, [FromForm] string Plate)
        {
            BackInfo bi = new BackInfo();
            bool flag = false;
            try
            {
                if (string.IsNullOrEmpty(GoodsName))
                {
                    GoodsName = "";
                }
                var db = DbHelper.GetDbConn();
                List<VerifyPlateList> lst = new List<VerifyPlateList>();
                DateTime dt;
                if (!string.IsNullOrEmpty(Date))
                {
                    if (!DateTime.TryParse(Date, out dt))
                    {
                        bi.code = 201;
                        bi.data = "";
                        bi.message = "请输入正确的日期";
                        return bi;
                    }

                    lst = db.Queryable<VerifyPlateList>().Where(it => it.VerifyDate.Date == dt.Date && it.GoodsName == GoodsName).ToList();
                    if (lst != null && lst.Count > 0)
                    {
                        foreach (var item in lst)
                        {
                            if (!string.IsNullOrEmpty(item.PlateList))
                            {
                                var arrayPlate = item.PlateList.Split(',');
                                for (int k = 0; k < arrayPlate.Length; k++)
                                {
                                    if (arrayPlate[k] == Plate)//此时为了比较完全相等的车号
                                    {
                                        flag = true;
                                        break;
                                    }
                                }
                            }
                            if (flag)//减少循环次数
                            {
                                break;
                            }
                        }
                    }
                    if (flag)
                    {
                        bi.code = 200;
                        bi.data = "验证通过";
                        bi.message = "验证通过,此车号:" + Plate + "已经设置可拉取货物";
                        return bi;
                    }
                    else
                    {
                        bi.code = 201;
                        bi.data = "验证未通过";
                        bi.message = "验证未通过,此车号:" + Plate + "未设置可拉取货物";
                        return bi;
                    }
                }
                else
                {
                    bi.code = 201;
                    bi.data = "";
                    bi.message = "请输入正确的日期";
                    return bi;
                }
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "";
                bi.message = "查询出错";
                logger.LogError("CommonController-->VerifyPlate:验证车牌号出错" + ex.ToString());
                return bi;
            }
        }

        /// <summary>
        /// 根据数据类型查询信息--修改版
        /// </summary>
        /// <param name="Date">日期</param>
        /// <param name="CardType">类型</param>
        /// <param name="Plate">货物名字</param>
        /// <returns></returns>
        [HttpPost("GetTheSameDayGoodsByPlate")]
        public BackInfo GetTheSameDayGoodsByPlate([FromForm] string Date, [FromForm] string CardType, [FromForm] string Plate)
        {
            BackInfo bi = new BackInfo();
            bool flag = false;
            try
            {
                var db = DbHelper.GetDbConn();
                List<VerifyPlateList> lst = new List<VerifyPlateList>();
                DateTime dt;
                if (!string.IsNullOrEmpty(Date))
                {
                    if (!DateTime.TryParse(Date, out dt))
                    {
                        bi.code = 201;
                        bi.data = "";
                        bi.message = "请输入正确的日期";
                        return bi;
                    }
                    if (string.IsNullOrEmpty(CardType))
                    {
                        bi.code = 201;
                        bi.data = "";
                        bi.message = "请输入制卡类型";
                        return bi;
                    }

                    lst = db.Queryable<VerifyPlateList>().Where(it => it.VerifyDate.Date == dt.Date && it.CardType == CardType).ToList();
                    List<VerifyPlateList> verifyPlateListAll = new List<VerifyPlateList>();
                    if (lst != null && lst.Count > 0)
                    {
                        foreach (var item in lst)
                        {
                            if (!string.IsNullOrEmpty(item.PlateList))
                            {
                                var arrayPlate = item.PlateList.Split(',');
                                for (int k = 0; k < arrayPlate.Length; k++)
                                {
                                    if (arrayPlate[k] == Plate)//此时为了比较完全相等的车号
                                    {
                                        if (!verifyPlateListAll.Exists(t=>t.GoodsName == item.GoodsName && t.Sender == item.Sender && t.Receiver == item.Receiver && t.CardType == item.CardType))
                                        {
                                            item.PlateList = Plate;
                                            if (item.PiCi != null && item.PiCi != "")
                                            {
                                                int pici_ = 0;
                                                if (item.PiCi == "空")
                                                {
                                                    item.PiCi = "";
                                                }
                                                else if (!int.TryParse(item.PiCi, out pici_))
                                                {
                                                    item.PiCi = "";//如果不能转成数字，则认为是空，因为需求说的是输入数字，故自助机要求必须是数字或为空
                                                }
                                            }
                                            if (item.PiCi == null)
                                            {
                                                item.PiCi = "";
                                            }
                                            verifyPlateListAll.Add(item);
                                        }
                                        flag = true;
                                        break;
                                    }
                                }
                            }                            
                        }
                    }
                    //去一下重：规则，1当货名不同且收货单位、发货单位都不为空时
                    if (flag)
                    {
                        bi.code = 200;
                        bi.data = JsonConvert.SerializeObject(verifyPlateListAll);
                        bi.message = "验证通过,此车号:" + Plate + "已经设置可拉取货物";
                        return bi;
                    }
                    else
                    {
                        bi.code = 201;
                        bi.data = "验证未通过";
                        bi.message = "验证未通过,此车号:" + Plate + "未设置可拉取货物";
                        return bi;
                    }
                }
                else
                {
                    bi.code = 201;
                    bi.data = "";
                    bi.message = "请输入正确的日期";
                    return bi;
                }
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "";
                bi.message = "查询出错";
                logger.LogError("CommonController-->VerifyPlate:验证车牌号出错" + ex.ToString());
                return bi;
            }
        }


        /// <summary>
        /// 新增 车牌验证数据
        /// </summary>
        /// <param name="insertObj">自定义基础数据</param>
        /// <returns></returns>
        [HttpPost("AddVerifyPlate")]
        public BackInfo AddVerifyPlate(VerifyPlateList insertObj)
        {
            BackInfo bi = new BackInfo();
            try
            {
                if (insertObj == null || insertObj.GoodsName == "" || insertObj.PlateList == "")
                {
                    bi.code = 201;
                    bi.data = "字段存在空";
                    bi.message = "新增数据失败：数据字段不能为空。";
                }

                var db = DbHelper.GetDbConn();
                List<VerifyPlateList> listResult = db.Queryable<VerifyPlateList>()
                    .Where(it => it.GoodsName == insertObj.GoodsName && it.VerifyDate == insertObj.VerifyDate)//in 查询
                    .ToList();
                //判断是否存在此数据
                if (listResult != null && listResult.Count != 0)
                {
                    bi.code = 201;
                    bi.data = "重复";
                    bi.message = "新增数据失败：数据不能重复。";
                    return bi;
                }
                //03 返回插入行数
                int iExeCount = db.Insertable(insertObj).IgnoreColumns(it => it.Id).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    bi.code = 200;
                    bi.data = "新增成功";
                    bi.message = "新增成功";
                    return bi;
                }
                else
                {
                    bi.code = 201;
                    bi.data = "新增数据失败";
                    bi.message = "新增数据失败";
                    return bi;
                }
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "系统内部错误";
                bi.message = "系统内部错误";
                logger.LogError("CommonController-->AddVerifyPlate:" + ex.ToString());
                return bi;
            }
        }
        /// <summary>
        /// 修改 车牌验证数据
        /// </summary>
        /// <param name="updataObj">自定义基础数据</param>
        /// <returns></returns>
        [HttpPost("UpdataVerifyPlate")]
        public BackInfo UpdataVerifyPlate(VerifyPlateList updataObj)
        {
            BackInfo bi = new BackInfo();
            try
            {
                var db = DbHelper.GetDbConn();
                if (db.Queryable<VerifyPlateList>().Where(it => it.VerifyDate == updataObj.VerifyDate
                && it.GoodsName == updataObj.GoodsName && it.Id != updataObj.Id).Any())
                {
                    bi.code = 201;
                    bi.data = "更新数据失败";
                    bi.message = "更新数据失败,数据重复。";
                    logger.LogError("SSMachineController-->UpdataVerifyPlate:更新数据失败,此数据重复");
                    return bi;
                }

                //信息安全的东西报表导入统计的，
                if (updataObj == null || updataObj.GoodsName == "" || updataObj.PlateList == "")
                {
                    bi.code = 201;
                    bi.data = "字段空";
                    bi.message = "修改数据失败：数据字段不能为空。";
                }

                //返回行数
                int iExeCount = db.Updateable(updataObj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    bi.code = 200;
                    bi.data = "更新成功";
                    bi.message = "更新成功";
                    return bi;
                }
                else
                {
                    bi.code = 201;
                    bi.data = "更新失败";
                    bi.message = "更新失败";
                    return bi;
                }
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "系统内部错误";
                bi.message = "系统内部错误";
                logger.LogError("CommonController-->UpdataVerifyPlate:" + ex.ToString());
                return bi;
            }
        }

        /// <summary>
        /// 删除 车牌验证数据
        /// </summary>
        /// <param name="obj">实体，但只用id</param>
        /// <returns></returns>
        [HttpPost("DeleteVerifyPlate")]
        public BackInfo DeleteVerifyPlate(VerifyPlateList obj)
        {
            BackInfo bi = new BackInfo();
            string msg = "";
            try
            {
                var db = DbHelper.GetDbConn();
                var result = db.Deleteable<VerifyPlateList>().Where(new VerifyPlateList() { Id = obj.Id }).ExecuteCommand();
                if (result == 1)
                {
                    bi.code = 200;
                    bi.data = "删除数据成功";
                    bi.message = "删除数据成功";
                    return bi;
                }
                else
                {
                    bi.code = 201;
                    bi.data = "删除数据失败";
                    bi.message = "删除数据失败";
                    return bi;
                }
            }
            catch (Exception ex)
            {
                msg = "CommonController-->DeleteVerifyPlate:删除出错" + ex.ToString();
                logger.LogError(msg);
                bi.code = 500;
                bi.data = "删除出错";
                bi.message = msg;
                return bi;
            }
        }

        #endregion

        #region 发货单位（自助机）
        //因为那个表里面会去进行更新

        /// <summary>
        /// 查询所有货物信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetSenderListSelefMachine")]
        public ContentResult GetSenderListSelefMachine()
        {
            try
            {
                var db = DbHelper.GetDbConn();
                List<ProductList> lst = new List<ProductList>();
                lst = db.Queryable<ProductList>().ToList();
                if (lst != null)
                {
                    return Content(InterfaceUtil.GetJsonObject(200, lst.Count, lst, "查询成功").ToString());
                }
                else
                {
                    logger.LogError("CommonController-->GetProductList:查询货物信息失败");
                    return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询失败").ToString());
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->GetProductList:" + ex.ToString());
                return Content(InterfaceUtil.GetJsonObject(201, 0, "", "查询出错").ToString());
            }
        }

        /// <summary>
        /// 根据货物查询信息
        /// </summary>
        /// <param name="Product">货物</param>
        /// <returns></returns>
        [HttpPost("GetSenderListSelefMachineByParameter")]
        public BackInfo GetSenderListSelefMachineByParameter([FromForm] string Product)
        {
            BackInfo bi = new BackInfo();
            try
            {
                var db = DbHelper.GetDbConn();
                List<ProductList> lst = new List<ProductList>();
                if (!string.IsNullOrEmpty(Product))
                {
                    lst = db.Queryable<ProductList>().Where(it => it.product.Contains(Product)).ToList();
                }
                else
                {
                    lst = db.Queryable<ProductList>().ToList();
                }
                bi.code = 200;
                bi.data = lst;
                bi.message = "查询成功";
                return bi;
            }
            catch (Exception ex)
            {
                bi.code = 500;
                bi.data = "";
                bi.message = "查询出错";
                logger.LogError("CommonController-->GetReceiverByParameter:查询自定义基础数据信息出错" + ex.ToString());
                return bi;
            }
        }

        /// <summary>
        /// 新增 货物
        /// </summary>
        /// <param name="insertObj">货物</param>
        /// <returns></returns>
        [HttpPost("AddSenderListSelefMachine")]
        public BackInfo AddSenderListSelefMachine(ProductList insertObj)
        {
            try
            {
                //01 数据字段长度判断
                string msg = "";
                if (insertObj == null || insertObj.product == "")
                {
                    logger.LogError(msg);
                    return new BackInfo { code = 201, message = "新增数据失败：货物字段不能为空。" };
                }
                //02 数据项重复判断
                var db = DbHelper.GetDbConn();
                List<ProductList> listResult = db.Queryable<ProductList>()
                    .Where(it => it.product == insertObj.product)//in 查询
                    .ToList();
                //判断是否存在此code
                if (listResult != null && listResult.Count != 0)
                {
                    logger.LogError("CommonController-->AddProductList:新增数据失败");
                    string tipMsg = "新增数据失败,货物不能重复";
                    return new BackInfo { code = 201, message = tipMsg };
                }
                //03 返回插入行数
                int iExeCount = db.Insertable(insertObj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new BackInfo { code = 200, message = "新增成功" };
                }
                else
                {
                    LogToDB("ProductList", "新增", JsonConvert.SerializeObject(insertObj), "失败", nameof(AddProductList) + "新增数据失败");
                    return new BackInfo { code = 201, message = "新增数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->AddProductList:" + ex.ToString());
                LogToDB("ProductList", "新增", JsonConvert.SerializeObject(insertObj), "出错", nameof(AddProductList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }


        /// <summary>
        /// 修改 货物
        /// </summary>
        /// <param name="obj">货物</param>
        /// <returns></returns>
        [HttpPost("UpdataSenderListSelefMachine")]
        public BackInfo UpdataSenderListSelefMachine(ProductList obj)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                if (db.Queryable<ProductList>().Where(it => it.id != obj.id && it.product == obj.product).Any())
                {
                    logger.LogError("CommonController-->UpdataProductList:更新数据失败,货物重复");
                    return new BackInfo { code = 201, message = "更新数据失败,货物重复。" };
                }
                //返回行数
                int iExeCount = db.Updateable(obj).ExecuteCommand(); //都是参数化实现                
                if (iExeCount == 1)
                {
                    return new BackInfo { code = 200, message = "修改成功" };
                }
                else
                {
                    logger.LogError("CommonController-->UpdataProductList:更新数据失败");
                    LogToDB("ProductList", "修改", JsonConvert.SerializeObject(obj), "失败", nameof(UpdataProductList) + "更新数据失败");
                    return new BackInfo { code = 201, message = "更新数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->UpdataProductList:" + ex.ToString());
                LogToDB("ProductList", "修改", JsonConvert.SerializeObject(obj), "出错", nameof(UpdataProductList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }


        /// <summary>
        /// 删除 货物
        /// </summary>
        /// <param name="obj">实体，但只用id</param>
        /// <returns></returns>
        [HttpPost("DeleteSenderListSelefMachine")]
        public BackInfo DeleteSenderListSelefMachine(ProductList obj)
        {
            try
            {
                var db = DbHelper.GetDbConn();
                var result = db.Deleteable<ProductList>().Where(new ProductList() { id = obj.id }).ExecuteCommand();
                string msg = "";
                if (result == 1)
                {
                    msg = "CommonController-->DeleteProductList:删除成功";
                    logger.LogError(msg);
                    return new BackInfo { code = 200, message = "删除成功" };
                }
                else
                {
                    logger.LogError("CommonController-->DeleteProductList:删除数据失败");
                    LogToDB("ProductList", "删除", JsonConvert.SerializeObject(obj), "失败", nameof(DeleteReceiverList) + "删除数据失败");
                    return new BackInfo { code = 201, message = "删除数据失败" };
                }
            }
            catch (Exception ex)
            {
                logger.LogError("CommonController-->DeleteProductList:" + ex.ToString());
                LogToDB("ProductList", "删除", JsonConvert.SerializeObject(obj), "出错", nameof(DeleteReceiverList) + "系统内部错误" + ex.ToString());
                return new BackInfo { code = 500, message = "系统内部错误" };
            }
        }

        #endregion
    }
}
